
import { MineModel } from '../../models/mine'
const mineModel = new MineModel()
import { AppModel } from '../../models/app.js'
const ModelApp = new AppModel()
const App = getApp()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    visible: Boolean,
    userType: Number,
    code: String,
    iconShow: {
      type: Boolean,
      default: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    iphoneX: App.globalData.isIphoneX
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 关闭closeService
    closeService() {
      this.setData({
        visible: false
      })
    },

    getPhoneNumber: function(e) {
      const self = this
      console.log(e.detail.errMsg)
      if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
        App.WxService.showToast({
          title: '您取消了授权',
          icon: 'none'
        })
      } else if (e.detail.errMsg == 'getPhoneNumber:ok') {
        const params = {
          code: this.properties.code,
          encrypteData: e.detail.encryptedData,
          iv: e.detail.iv,
          regType: 3
        }
        mineModel
          .wx_bind_phone(params)
          .then(res => {
            wx.showToast({
              title: '手机号绑定成功',
              duration: 500,
              icon: 'none',
              success: function() {
                self.setData({
                  visible: false
                })
                // 绑定成功更新 App.globalData.userInfo
                ModelApp._getVipInfo().then(res => {
                  App.globalData.userInfo = res.data.userInfo
                })
              }
            })
          })
          .catch()
      }
      // var code = wx.getStorageSync('logincode');
    }
  }
})
